﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="HtmlContent.ascx.cs" Inherits="VLUNewsUI.VLUNews.HtmlContent" %>
<%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>
<%@ Register TagPrefix="dnn" TagName="Text" Src="~/controls/texteditor.ascx" %>
<%@ Register TagPrefix="dnn" TagName="urlcontrol" Src="~/controls/urlcontrol.ascx" %>
<%@ Register TagPrefix="dnn" TagName="SectionHead" Src="~/controls/SectionHeadControl.ascx" %>
<%@ Register TagPrefix="dnn" TagName="Url" Src="~/controls/UrlControl.ascx" %>
<%@ Register TagPrefix="dnn" Namespace="DotNetNuke.UI.WebControls" Assembly="DotNetNuke" %>
<%--<%@ Register TagPrefix="dnn" Namespace="DotNetNuke.Web.Client.ClientResourceManagement" Assembly="DotNetNuke.Web.Client" %>--%>

<div class="dnnForm dnnEditHtmlContent dnnClear" id="dnnEditHtmlContent">
    <div class="erBasicSettings" id="erBasicSettings">
        <div class="erbsContent dnnClear">
            <fieldset>
                 <div class="dnnFormItem">
                    <dnn:Label ID="plSitemapName" runat="server" ResourceKey="SitemapName" ControlName="txtSitemapName" />
                    <asp:DropDownList ID="ddlSitemapName" runat="server" AutoPostBack="true" CssClass="dnnFormRequired"/>
                    <asp:RequiredFieldValidator ID="valSitemapName" CssClass="dnnFormMessage dnnFormError" runat="server" resourcekey="txtSitemapID" ControlToValidate="ddlSitemapName" InitialValue="-1" Display="Dynamic" />
                    <%--<asp:CompareValidator ID="valSitemapName" runat="server" ValueToCompare="0" ControlToCompare="ddlSitemapName" Operator="NotEqual" Display="Dynamic" />--%>
                    <asp:Image ID="imgIsSecurity" runat="server" CssClass="imgIsSecurity" />
<%--                    <asp:TextBox ID="txtSitemapName" runat="server" CssClass="dnnFormRequired" MaxLength="50" Enabled="false" />
                    <asp:RequiredFieldValidator ID="valSitemapName" CssClass="dnnFormMessage dnnFormError" runat="server" resourcekey="valSitemapName" ControlToValidate="txtSitemapName" Display="Dynamic" />
--%>                    <%--<asp:RegularExpressionValidator ID="valHtmlContentName2" 
                        CssClass="dnnFormMessage dnnFormError" runat="server" 
                        resourcekey="valHtmlContentName2" ControlToValidate="txtHtmlContentName" 
                        Display="Dynamic" ValidationExpression="\w+([-.]\w+)*\.\w+([-.]\w+)*" />--%>
                </div>               
                <div class="dnnFormItem">
                    <dnn:Label ID="plTitle" runat="server" ResourceKey="Title" ControlName="txtTitle" />
                    <asp:TextBox ID="txtTitle" runat="server" CssClass="dnnFormRequired" MaxLength="500" />
                    <asp:RequiredFieldValidator ID="valTitle" CssClass="dnnFormMessage dnnFormError" runat="server" resourcekey="valTitle" ControlToValidate="txtTitle" Display="Dynamic" />
                    <%--<asp:RegularExpressionValidator ID="valHtmlContentName2" 
                        CssClass="dnnFormMessage dnnFormError" runat="server" 
                        resourcekey="valHtmlContentName2" ControlToValidate="txtHtmlContentName" 
                        Display="Dynamic" ValidationExpression="\w+([-.]\w+)*\.\w+([-.]\w+)*" />--%>
                </div>
                <div class="dnnFormItem">
                    <dnn:Label ID="plDescription" runat="server" ResourceKey="Description" ControlName="txtDescription" />
                    <asp:TextBox ID="txtDescription" runat="server" CssClass="dnnFormRequired" MaxLength="2000" TextMode="MultiLine"/>
                    <asp:RequiredFieldValidator ID="valDescription" CssClass="dnnFormMessage dnnFormError" runat="server" resourcekey="valDescription" ControlToValidate="txtDescription" Display="Dynamic" />
                </div>
                <%--Themnail image--%>
                <div class="dnnFormItem">
                    <dnn:Label ID="plImage" runat="server" ResourceKey="Image"/>
                    <asp:Image ID="imgThemnail" runat="server" CssClass="imgThemnail" />
                </div>
                <asp:Panel CssClass="dnnFormItem" ID="pnlCommandThemnail" runat="server">
                    <div id="divThemnailImages" runat="server" class="popupbox" visible="false">
                        <div class="divThemnailImagesClose">
                            <asp:ImageButton runat="server" ID="lblThemnailClose" CssClass="PopupClose" resourcekey="lblThemnailClose" CausesValidation="false" ImageUrl='~/images/close-icn.png'/>
                        </div>
                        <div style="height: 88%; width: 100%; overflow: Auto">
                            <asp:DataList ID="dtlImages" runat="server" RepeatColumns="3" Height="100%">
                                <ItemTemplate>
                                    <asp:ImageButton ID="imgThemnail" runat="server" ImageUrl='<%# "~/Portals/" + PortalId + "/" + Eval("RelativePath") %>' CausesValidation="false" />
                                </ItemTemplate>
                            </asp:DataList>
                        </div>
                    </div>
                    <div class="divCommandThemnail">
                        <div class="SelectThemnail">
                            <asp:LinkButton ID="cmdSelectThemnail" resourcekey="cmdSelectThemnail" Text="Chọn ảnh khác" runat="server" CausesValidation="False"/>
                        </div>
                    </div>
                </asp:Panel>
                <div id="divUrlUploadImage" runat="server" class="divUrlUploadImage">
                    <dnn:URL ID="urlUploadImage" runat="server" UrlType="F" Width="325" 
                    FileFilter="png,jpg,jpeg,gif"
                    ShowDatabase="False" 
                    ShowFiles="True" 
                    ShowImages="False" 
                    ShowLog="False" 
                    ShowNewWindow="False" 
                    ShowNone="False" 
                    ShowSecure="False" 
                    ShowTabs="False"
                    ShowTrack="False"
                    ShowUpLoad="True"
                    ShowUrls="False" 
                    ShowUsers="False" 
                    Required="False"/>
                </div>
                <%--Paste from word--%>
                <asp:Panel CssClass="dnnFormItem" ID="pnlCommandPaste" runat="server">
                    <div>
                        <%--<asp:LinkButton ID="cmdPastShow" resourcekey="cmdPastShow" Text="Dán từ word" runat="server" CausesValidation="False" CssClass="cmdPastShow"/>--%>
                        <a id="cmdPastShow" class="cmdPastShow" href="javascript:cmdPastShow();" >Dán từ word</a>
                        <%--<input type="button" id="cmdPastShow" value="Dán từ word" class="cmdPastShow" onclick="cmdPastShow"/>--%>
                        <div class="popupboxPaste" id="popupboxPaste" runat="server" >
                            <div class="divWordMenu">
                                <a id="cmdPaste" class="cmdPaste" href="javascript:cmdPaste();" > Chấp nhận </a>
                                <a id="cmdPasteClose" class="cmdPasteClose" href="javascript:cmdPasteClose();" > Đóng </a>
                                <%--<input id="cmdPaste" type="button" value=" Chấp nhận " class="cmdPaste"/>--%>
                                <%--<input id="cmdPasteClose" type="button" value=" Đóng " class="cmdPasteClose"/>--%>
                            </div>
                            <div id="divPaste" contenteditable="true" onpaste="javascript:divOnPaste();" style="height: 98%; width: 100%; overflow: Auto"></div>
                        </div>
                    </div>
                </asp:Panel>
                <div class="dnnFormItem">
                    <dnn:Label ID="plContent" runat="server" ResourceKey="Content" ControlName="txtContent" />
                    <%--<asp:TextBox ID="txtContentDisable" runat="server" MaxLength="1000" TextMode="MultiLine" Enabled="false"/>--%>
                    <dnn:Text ID="txtContent" runat="server" MaxLength="1000"/>
                    <asp:RequiredFieldValidator ID="valContent" CssClass="dnnFormMessage dnnFormError" runat="server" resourcekey="valContent" ControlToValidate="txtContent" Display="Dynamic" />
                    <br />
                    <br />
                    <asp:Label runat="server" ID="lblContent" CssClass="lblContent"></asp:Label>
                </div>
                <%--<div class="dnnFormItem">
                    <dnn:Label ID="plImage" runat="server" ResourceKey="Image"/>
                    <dnn:urlcontrol runat="server" ID="uplImage" 
                    showfiles="True" ShowUpLoad="True" showUrls="False" shownewwindow="False" showtrack="False" showlog="False" UrlType="U" showtabs="False" FileFilter="jpg,jpeg,gif,png"/>
                </div>--%>
            </fieldset>
        </div>
    </div>

    <div runat="server" id="pnlComment" class="dnnNewsComment" visible="false">
        <div runat="server" id="pnlCommentCommand" Visible="false">
            <dnn:Label ID="plComment" runat="server" ResourceKey="Comment" ControlName="txtComment" />
            <asp:TextBox ID="txtComment" runat="server" MaxLength="2000" TextMode="MultiLine" />
            <asp:LinkButton ID="cmdComment" resourcekey="cmdComment" runat="server" CssClass="dnnPrimaryAction"/>
        </div>
        <asp:datagrid id="dgdComment" Width="98%" AutoGenerateColumns="False" 
            runat="server" BorderStyle="None" GridLines="None" CssClass="dnnGrid">
            <headerstyle cssclass="dnnGridHeader" verticalalign="Top"/>
	        <itemstyle cssclass="dnnGridItem" horizontalalign="Left"/>
	        <alternatingitemstyle cssclass="dnnGridAltItem" />
	        <edititemstyle cssclass="dnnFormInput" />
	        <selecteditemstyle cssclass="dnnFormError" />
	        <footerstyle cssclass="dnnGridFooter" />
	        <pagerstyle cssclass="dnnGridPager" />
		    <columns>
		        <asp:boundcolumn DataField="Comment" HeaderText="Comment" />
		        <asp:boundcolumn DataField="OwnerName" HeaderText="Commenter" />
		    </columns>
	    </asp:datagrid>
    </div>
    <ul class="dnnActions dnnClear">
        <li><asp:LinkButton ID="cmdUpdate" resourcekey="cmdUpdate" runat="server" CssClass="dnnPrimaryAction" Visible="false"/></li>
        <li><asp:LinkButton ID="cmdGet" resourcekey="cmdGet" runat="server" CssClass="dnnSecondaryAction" Visible="false"/></li>
        <li><asp:LinkButton ID="cmdSend" resourcekey="cmdSend" runat="server" CssClass="dnnSecondaryAction" Visible="false"/></li>
        <li><asp:LinkButton ID="cmdReturn" resourcekey="cmdReturn" runat="server" CssClass="dnnSecondaryAction" Visible="false"/></li>
        <li><asp:LinkButton ID="cmdApprove" resourcekey="cmdApprove" runat="server" CssClass="dnnSecondaryAction" Visible="false"/></li>
        <li><asp:LinkButton ID="cmdDown" resourcekey="cmdDown" runat="server" CssClass="dnnSecondaryAction" CausesValidation="False" Visible="false"/></li>
        <li><asp:LinkButton ID="cmdDeleteTemp" resourcekey="cmdDelete" runat="server" CssClass="dnnSecondaryAction" CausesValidation="False" Visible="false"/></li>
        <li><asp:LinkButton ID="cmdDelete" resourcekey="cmdDelete" runat="server" CssClass="dnnSecondaryAction" CausesValidation="False" Visible="false"/></li>
        <li><asp:LinkButton ID="cmdCancel" resourcekey="cmdCancel" runat="server" CssClass="dnnSecondaryAction" CausesValidation="False"/></li>
        <%--<li><asp:HyperLink ID="cmdCancel" resourcekey="cmdCancel" runat="server" CssClass="dnnSecondaryAction" CausesValidation="False" /></li>--%>
    </ul>
</div>

<%--<script type="text/javascript" src="<%= ControlPath%>js/popup.js"/>--%>

<script type="text/javascript">

    function cmdPastShow(e) {
        var txtContent = $('.reContentCell').find('iframe').contents().find('body');
        $('#divPaste').html(txtContent.html());
        $(".popupboxPaste").show();
    };

    function cmdPaste(e) {
        var txtContent = $('.reContentCell').find('iframe').contents().find('body');
        //alert(txtContent.html());
        txtContent.html($('#divPaste').html());
        $('#divPaste').html("")
        $(".popupboxPaste").hide();
    };

    function cmdPasteClose(e) {
        $(".popupboxPaste").hide();
    };

    function divOnPaste(e) {
        //$('.reContentCell').find('iframe').contents().find('body').bind('paste', 'input, textarea', function (event) {
        var items = (event.clipboardData || event.originalEvent.clipboardData).items;
        for (var i = 0; i < items.length; i++) {
            if (items[i].kind === "file" && items[i].type.indexOf("image") !== -1) {
                // get the blob
                var imageFile = items[i].getAsFile();

                // read the blob as a data URL
                var fileReader = new FileReader();
                fileReader.onloadend = function (e) {
                    // create an image
                    var image = document.createElement("IMG");
                    image.src = this.result;

                    // insert the image
                    var range = window.getSelection().getRangeAt(0);
                    range.insertNode(image);
                    range.collapse(false);

                    // set the selection to after the image
                    var selection = window.getSelection();
                    selection.removeAllRanges();
                    selection.addRange(range);
                };

                // TODO: Error Handling!
                // fileReader.onerror = ...

                fileReader.readAsDataURL(imageFile);

                // prevent the default paste action
                //e.preventDefault();

                // only paste 1 image at a time
                break;
            }
        }
    };
//    $('#divPaste').on('paste', function (event) {
//        alert("aaa");
//    });

    $(document).ready(function () {



        $('.urlControlFileRow .dnnFormItem').hide();
        $('#<%= valSitemapName.ClientID %>').hide();

    });

</script>
    